<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style>
        .orgui-textbox{
            position: relative;
            border: 1px solid #e9e9e9;
            height: 18px;
            line-height: 18px;
            width: 500px;
            border-radius: 4px;
        }
    </style>
</head>
<body class="iframeBody">
<form id="prjFlowAuthCtrl_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="fieldBox col_100">
            <div class="label">所属机构</div>
            <div class="field">
                <input name="passiveCtrlOrgCdNm" id="passiveCtrlOrgCdNm" type="text" disabled="true" class="orgui-textbox" value="${prjFlowAuthCtrlVO.buOrgCdNm}" validate="{required:true}" />
                <span class="requiredSymbol">*</span>
                <input name="passiveCtrlOrgCd" id="passiveCtrlOrgCd" type="text" hidden="true" <%--value="${prjFlowAuthCtrlVO.buOrgCd}"--%>/>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">被控制人</div>
            <div class="field">
                <input type="text" id="passiveCtrlRlNm" name="passiveCtrlRlNm" class="ui-textbox"
                        <c:if test="${editFlag == '2'}"> disabled="true" </c:if>
                       data-value="${prjFlowAuthCtrlVO.passiveCtrlRlNm}" validate="{required:true}"/>
                <a class="sq-button-hasicon" href="javascript:initFlowEvent()"><i class="sqBtnIco_1"></i></a>
                <span class="requiredSymbol">*</span>
                <input name="passiveCtrlId" id="passiveCtrlId" type="text" hidden="true"/>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">控制内容</div>
            <div class="field">
                <input type="text" id="ctrlContent" name="ctrlContent" data-value="${prjFlowAuthCtrlVO.ctrlContent}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}"/>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">控制项目类型</div>
            <div class="field">
                <input type="text" id="ctrlPrjTypCd" name="ctrlPrjTypCd" data-value="${prjFlowAuthCtrlVO.ctrlPrjTypCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}"/>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">添加原因</div>
            <div class="field">
                <input type="text" id="ctrlReason" name="ctrlReason" data-value="${prjFlowAuthCtrlVO.ctrlReason}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}"/>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">发送至录单员</div>
            <div class="field">
                <select name="isAllowSendToRecoder" id="isAllowSendToRecoder" data-value="${prjFlowAuthCtrlVO.isAllowSendToRecoder}" validate ="{required:true,select:true}">
                    <option value="1">允许</option>
                    <option value="0">禁止</option>
                </select>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">控制时间</div>
            <div class="field">
                <input name="ctrlStartDt" id="ctrlStartDt" type="text" class="ui-datepicker" value="${ctrlStartDtVO}"
                       validate="{required:true}" />
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">控制结束时间</div>
            <div class="field">
                <input name="ctrlEndDt" id="ctrlEndDt" type="text" class="ui-datepicker" value="${ctrlEndDtVO}"
                       validate="{required:true}" />
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">添加时间</div>
            <div class="field">
                <input name="crtTm" id="crtTm" type="text" class="ui-textbox" value="${crtTm}" readonly="readonly">
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">添加人</div>
            <div class="field">
                <input name="crtUsrNm" id="crtUsrNm" type="text" class="ui-textbox" value="${currentUserName}" readonly="readonly">
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">备注</div>
            <div class="field">
                <textarea name="ctrlRem" id="ctrlRem" rows="7" class="l-textarea" value="${prjFlowAuthCtrlVO.ctrlRem}"
                          style="width:99%" validate="{maxlength:150}" >${prjFlowAuthCtrlVO.ctrlRem}</textarea>
            </div>
        </div>
        <!-- hide data -->
        <div class="fieldBox col_100" style="display:none;">
            <input id="prjFlowAuthCtrlId" type="text" class="ui-textbox" value="${id}">
        </div>
    </div>
</form>
<script>
    var id = '${id}';//初始值
    var editFlag = '${editFlag}';
    var searchOrgTree = null;
    $(function () {
        //控制内容下拉框
        var _ctrlContentJSON = ${ctrlContentJSON};
        $("#ctrlContent").ligerComboBox({
            isShowCheckBox: true, isMultiSelect: true,
            data: _ctrlContentJSON,
            valueField: 'key',
            textField: 'value'
        });
        //控制项目类型下拉框
        var _projectTypeJSON = ${projectTypeJSON};
        $("#ctrlPrjTypCd").ligerComboBox({
            isShowCheckBox: true, isMultiSelect: true,
            data: _projectTypeJSON,
            valueField: 'key',
            textField: 'value'
        });
        //添加原因下拉框
        var _ctrlReasonJSON = ${ctrlReasonJSON};
        $("#ctrlReason").ligerComboBox({
            isShowCheckBox: true, isMultiSelect: true,
            data: _ctrlReasonJSON,
            valueField: 'key',
            textField: 'value'
        });
        $("#ctrlStartDt").ligerDateEditor({ showTime: true, width:"180", format:"yyyy-MM-dd hh:mm:ss"});
        $("#ctrlEndDt").ligerDateEditor({ showTime: true, width:"180", format:"yyyy-MM-dd hh:mm:ss"});
        initData();
        //初始化表单
        $("#prjFlowAuthCtrl_form").ligerForm({
            validate: true
        });
    });


    //定义父级调用事件
    frameElement.dialog.onOk = function () {
        save();
    }

    frameElement.dialog.onCancel = function () {
        frameElement.dialog.close();
    }

    //初始化事件
    function initFlowEvent(){
        if(frameElement && frameElement.dialog) {
            var dialog_data=frameElement.dialog.get("_data");
            dialog_data.openDialogForChooseUsr();
        }
    }

    //保存
    function save() {
        var ligerForm = liger.get("prjFlowAuthCtrl_form");
        if (!ligerForm.valid()) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = ligerForm.getData();

        //校验时间
        var begin = data.ctrlStartDt;
        var end = data.ctrlEndDt;
        var beginDate = new Date(begin);
        var endDate = new Date(end);
        if (beginDate.getTime() - endDate.getTime() > 0) {
            $.ligerDialog.SQalert({content: "开始时间不能大于结束时间!", SQ_type: "warning"});
            return false;
        }

        var id = $("#prjFlowAuthCtrlId").val();

        var wait_dialog = $.ligerDialog.SQalert({
            content: LogUtils.LOG_CMM_LOADING,
            SQ_type: "waitting",
            onClose: function () {
            }
        });

        var _url = '<%=path%>/flowauth/prjFlowAuthCtrl/add.do';
        if (id != "") {
            //id存在时，做修改操作
            _url = '<%=path%>/flowauth/prjFlowAuthCtrl/modify.do';
            data["id"] = id;
        }

        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: '<%=path%>/flowauth/prjFlowAuthCtrl/checkCtrl.do',
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    var msgData = JsonUtils.parse(msg.data);
                    var ctrlRlNm = "";
                    var _ids = [];
                    for (var i in msgData) {
                        var rl = msgData[i];
                        if (ctrlRlNm.indexOf(rl)==-1) {
                            ctrlRlNm += " " + msgData[i] + " ";
                        }
                        _ids.push(i);
                    }
                    $.ligerDialog.confirm('被控制人' + ctrlRlNm + '已存在生效限制，需将原记录禁用后生效', function (flag) {
                        if (flag == false) {
                            return;
                        }
                        data["ids"] = JSON.stringify(_ids);
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: data,
                            url: _url,
                            success: function (msg) {
                                wait_dialog.close();
                                if (msg.success == 1) {
                                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                                    parent.grid.reload();
                                    frameElement.dialog.close();
                                } else {
                                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                                }
                            }
                        });
                    });
                } else {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: data,
                        url: _url,
                        success: function (msg) {
                            wait_dialog.close();
                            if (msg.success == 1) {
                                top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                                parent.grid.reload();
                                frameElement.dialog.close();
                            } else {
                                top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                            }
                        }
                    });
                }
            }
        });
    }

    function initData() {
        if (editFlag == "2") {
            //修改
            if (liger.get("passiveCtrlRlNm")) {
                liger.get("passiveCtrlRlNm").setAttribute("disabled","true");
            }
        }
    }

    if(frameElement && frameElement.dialog) {
        frameElement.dialog.set("_subWin", this); //把这个窗口对象绑到父窗口的dialog对象上
    };
</script>
</body>
</html>